package pers.wang.toolset.redis.spring.boot.autoconfigure;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;

@Configuration(value = "toolsetRedisAutoConfigure")
public class RedisAutoConfigure {
	@Bean("toolsetStringRedisTemplate")
	public StringRedisTemplate stringRedisTemplate(LettuceConnectionFactory redisConnectionFactory) {
		StringRedisTemplate redisTemplate = new StringRedisTemplate(redisConnectionFactory);
		redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
		return redisTemplate;
	}

	@Bean
	public RedisUtil redisUtil(StringRedisTemplate toolsetStringRedisTemplate) {
		return new RedisUtil(toolsetStringRedisTemplate);
	}
}
